﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Security.Principal;

    using Csla;
    using Csla.Security;
using MarketPulse.BusinessLogic.Core.Criteria;

#endregion

namespace MarketPulse.BusinessLogic.Core.Security
{
    /// <summary>
    /// Class used to represent a security identity within the system. Interacts with a data factory to authenticate a user (based on the username and password supplied) 
    /// and retrieves a valid security identity (whether it's authenticated or not)
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.SecurityFactory, MarketPulse.DataAccess.Factory", "Fetch")]
    public class MarketPulseIdentity : CslaIdentity
    {

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private MarketPulseIdentity()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// Method used to retrieve a security identity based on the username and password supplied
                /// </summary>                
                /// <param name="username">The username to use to retrieve the security identity</param>
                /// <param name="password">The password to use to retrieve the security identity</param>
                /// <param name="profileTypeGUID">The type of profile to use to retrieve the security identity</param>
                /// <returns>A valid identity object</returns>
                internal static MarketPulseIdentity Get(string username, string password, Guid profileTypeGUID)
                {
                    return DataPortal.Fetch<MarketPulseIdentity>(new SystemAuthenticationCriteria(username, password, profileTypeGUID));
                }

                /// <summary>
                /// Method used to retrieve a security identity based on the username and password supplied
                /// </summary>                
                /// <param name="userGUID">The username to use to retrieve the security identity</param>
                /// <param name="privateKey">The private key to use to retrieve the security identity</param>
                /// <param name="profileTypeGUID">The type of profile to use to retrieve the security identity</param>
                /// <returns>A valid identity object</returns>
                internal static MarketPulseIdentity Get(Guid userGUID, string privateKey, Guid profileTypeGUID)
                {
                    return DataPortal.Fetch<MarketPulseIdentity>(new SystemAuthenticationCriteria(userGUID, privateKey, profileTypeGUID));
                }

            #endregion

        #endregion

    }
}